﻿using System;

namespace Flowertwig.Utils.Compression.General
{
    /// <summary>
    /// FastZipEvents supports all events applicable to <see cref="FastZip">FastZip</see> operations.
    /// </summary>
    public class FastZipEvents
    {
        /// <summary>
        /// Delegate to invoke when processing directories.
        /// </summary>
        public ProcessDirectoryDelegate ProcessDirectory;
		
        /// <summary>
        /// Delegate to invoke when processing files.
        /// </summary>
        public ProcessFileDelegate ProcessFile;

        /// <summary>
        /// Delegate to invoke when processing directory failures.
        /// </summary>
        public DirectoryFailureDelegate DirectoryFailure;
		
        /// <summary>
        /// Delegate to invoke when processing file failures.
        /// </summary>
        public FileFailureDelegate FileFailure;
		
        /// <summary>
        /// Raise the directory failure event.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="e">The exception for this event.</param>
        public void OnDirectoryFailure(string directory, Exception e)
        {
            if ( DirectoryFailure != null ) {
                ScanFailureEventArgs args = new ScanFailureEventArgs(directory, e);
                DirectoryFailure(this, args);
            }
        }
		
        /// <summary>
        /// Raises the file failure event.
        /// </summary>
        /// <param name="file">The file for this event.</param>
        /// <param name="e">The exception for this event.</param>
        public void OnFileFailure(string file, Exception e)
        {
            if ( FileFailure != null ) {
                ScanFailureEventArgs args = new ScanFailureEventArgs(file, e);
                FileFailure(this, args);
            }
        }
		
        /// <summary>
        /// Raises the ProcessFileEvent.
        /// </summary>
        /// <param name="file">The file for this event.</param>
        public void OnProcessFile(string file)
        {
            if ( ProcessFile != null ) {
                ScanEventArgs args = new ScanEventArgs(file);
                ProcessFile(this, args);
            }
        }
		
        /// <summary>
        /// Raises the ProcessDirectoryEvent.
        /// </summary>
        /// <param name="directory">The directory for this event.</param>
        /// <param name="hasMatchingFiles">Flag indicating if directory has matching files as determined by the current filter.</param>
        public void OnProcessDirectory(string directory, bool hasMatchingFiles)
        {
            if ( ProcessDirectory != null ) {
                DirectoryEventArgs args = new DirectoryEventArgs(directory, hasMatchingFiles);
                ProcessDirectory(this, args);
            }
        }
		
    }
}